<template>
  <div>
    <router-link to="/saleChance/AddSaleChance"><el-button>添加</el-button></router-link>
    <el-table
      :data="saleChanceList"
      :stripe="true"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="机会名称">
      </el-table-column>
      <el-table-column
        prop="description"
        label="描述">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="messageFrom"
        label="消息来源">
      </el-table-column>
      <el-table-column
        prop="linkman"
        label="联系人">
      </el-table-column>
      <el-table-column
        prop="tel"
        label="电话">
      </el-table-column>

      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button @click="deleteById(scope.row.id)" size="mini">删除</el-button>
          <el-button @click="updateStateById(2,scope.row.id)" size="mini" v-if="scope.row.messageState==1">成功</el-button>
          <el-button @click="updateStateById(3,scope.row.id)" size="mini" v-if="scope.row.messageState==1">失败</el-button>
          <router-link :to="'/saleChance/SalePlanList?cid='+scope.row.id"><el-button size="mini">查看销售计划</el-button></router-link>
          <router-link :to="'/saleChance/DisSaleChance?cid='+scope.row.id"><el-button size="mini">分配销售</el-button></router-link>
        </template>
      </el-table-column>
    </el-table>
    <router-view/>
  </div>
</template>

<script>
    export default {
        name: "saleChanceList",
      data(){
          return {
            saleChanceList:[],
            saleChance:{}
          }
      },
      created(){
        this.selectAll();
      },
      methods:{
        deleteById(id){
          this.axios.delete("/saleChance/delete/"+id).then((resp)=>{
            //提示保存成功信息
            this.$message.success("删除成功！");
            this.selectAll();
          });
        },
        selectAll(){
          //发出ajax请求请求后端代码
          let url="/saleChance/selectAll";
          this.axios.get(url).then((resp)=>{
            this.saleChanceList=resp.data;
          });
        },
        updateStateById(state,id){
          this.saleChance.id=id;
          this.saleChance.messageState=state;
          this.axios.put("/saleChance/updateStateById",this.saleChance).then((resp)=>{
            this.$message.success("状态修改成功！");
             this.selectAll();
          });
        }
      }
    }
</script>

<style scoped>

</style>
